# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_platform//platform_data:defs.bzl", "platform_data")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_binary")

package(default_visibility = ["//visibility:public"])

# Give QEMU a stable path.
# This prevents the runfiles location from being something like:
#     external/+_repo_rules+qemu/bin/qemu-system-arm
copy_file(
    name = "qemu-system-arm",
    src = "@qemu//:bin/qemu-system-arm",
    out = "qemu-system-arm",
    allow_symlink = True,
    visibility = ["//visibility:private"],
)

pw_py_binary(
    name = "unit_test_runner",
    srcs = [
        "lm3s6965evb_qemu_utils/unit_test_runner.py",
    ],
    main = "lm3s6965evb_qemu_utils/unit_test_runner.py",
    tags = ["manual"],
    deps = [
        ":lm3s6965evb_qemu_utils",
        "@rules_python//python/runfiles",
    ],
)

py_library(
    name = "lm3s6965evb_qemu_utils",
    srcs = [
        "lm3s6965evb_qemu_utils/__init__.py",
        "lm3s6965evb_qemu_utils/unit_test_runner.py",
    ],
    data = [
        ":qemu-system-arm",
    ],
    imports = ["."],
    tags = ["manual"],
    deps = [
        "@rules_python//python/runfiles",
    ],
)

platform_data(
    name = "exec_cfg_unit_test_runner",
    platform = "@local_config_platform//:host",
    target = ":unit_test_runner",
)
